package com.woniu40.petai_manager.web;


import com.woniu40.petai_manager.entity.Order;
import com.woniu40.petai_manager.result.ResponseResult;
import com.woniu40.petai_manager.service.OrderService;
import com.woniu40.petai_manager.vo.OrderVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @GetMapping("/findAll")
    @ApiOperation(value = "查询订单及订单详情列表")
    public ResponseResult<List<Order>> findAll(){
        ResponseResult<List<Order>> result = new ResponseResult<>();
        List<Order> all = orderService.findAll();
        result.setCode(200);
        result.setMessage("查询成功");
        result.setData(all);
        return result;
    }


    @PutMapping("/update")
    @ApiOperation(value = "更改订单")
    @ApiImplicitParam(name = "id",required = true,dataType = "Integer")
    public ResponseResult<String> update(Integer id){
        ResponseResult<String> result = new ResponseResult<>();
        int i = orderService.update(id);
        if (i!=0){
            result.setCode(200);
            result.setMessage("更新成功");
        }else {
            result.setCode(108);
            result.setMessage("更新失败");
        }
        return result;

    }





}
